<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/headMain.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<title>订单管理</title>
  </head>
  		<script type="text/javascript">
		function _delOrder(id) {
			if (confirm("删除订单吗？")) {
				$.post("${base}/order_deleteOrder/" + id, 
					function(data) {
						if (data && data.success) {
							alert(data.msg);
							$("#_orderGrid").jqGrid('setGridParam',{url: '${base}/order_getList/${shopId }'}).trigger("reloadGrid");
						} else {
							alert(data.msg);
						}
					}, 
				"json");
			}
		}
		
		function _viewOrder(id) {
			$("#_ordersDetails").dialog({
				height:450,width:900,resizable:false,modal:true
			}).load('${base}/order_orderDetails/' + id, function(){
					jQuery.div.util.hideLoading();
			});
		}
  		
		$(function(){
				$("#_orderGrid").jqGrid({
				   	url: "${base}/order_getList/${shopId }",
					datatype: "json",
				   	colNames:['ID','SHOPID', 'USID', '用户名', '姓名', '预定时间', '总金额', '订单状态', '订单说明', '接收时间', '操作'],
				   	colModel:[
				   		{name:'id',index:'id', hidden:true},
				   		{name:'shopid',index:'shopid', hidden:true},
				   		{name:'usid', index:'usid', hidden:true},
				   		{name:'regname', index:'regname', align:'center'},
				   		{name:'name', index:'name', hidden:true},
				   		{name:'createtime', index:'createtime', align:'center'},
				   		{name:'totalprice', index:'totalprice', align:'center'},
				   		{name:'status', index:'status', editable: false, formatter:'select', editoptions:{value:"0:未受理;1:已受理"}, align:'center'},
				   		{name:'orderdeclare', index:'orderdeclare', align:'left'},
				   		{name:'acceptime', index:'acceptime', align:'center'},
				   		{name:'ctrl', index:'ctrl', align:'center', sortable:false}
				   	],
				   	width:900,
				   	height:230,
				   	rowNum:10,
				   	rowList:[10,20,30],
				   	pager: '#_orderBar',
				   	sortname: 'id',
				    viewrecords: true,
				    sortorder: "desc",
					multiselect: false,
					jsonReader: {
						repeatitems : false
					},
					rownumbers : true,
					caption: "订单管理",
					afterInsertRow : function(rowid, data) {
						$("#_orderGrid").jqGrid(
								'setCell', 
								rowid, 
								'ctrl', 
								'<span class="view" va="' + data.id + '">查看</span>'+ 
								'|<span style="cursor:pointer;" onclick="_auditOrder(' + data.id + ',' + data.status + ');">' + (data.status == 1 ? '受理' : '不受理') + '</span>' +
								'|<span style="cursor:pointer;" onclick="_delOrder(' + data.id + ');">删除</span>', 
								{color:'green'}
						);
					},
					gridComplete: function() {
		                /*
		                var rowIds = $("#_orderGrid").jqGrid('getDataIDs');
		                for (var k=0; k<rowIds.length; k++) {
		                   var curRowData = $("#_orderGrid").jqGrid('getRowData', rowIds[k]);
		                   var curChk = $("#"+rowIds[k]+"").find(":checkbox");
		                   curChk.attr('name', 'oderId');
		                   curChk.attr('value', curRowData['id']);
		                }
		                */
		                //下面的方法解决点击弹出DIV只能弹出一次的问题
		                $(".view").each(function(n, m) {
		                	$(this).css("cursor", "pointer").bind("click", function(event){
				                $("#_ordersDetails").dialog("destroy");   //销毁dialog对象
				                $("#_ordersDetails").dialog({
									height:450,width:900,resizable:false,modal:true
								}).load('${base}/order_orderDetails/' + $(this).attr("va"), function() {
										jQuery.div.util.hideLoading();
								});
            				});
		                });
            		}
				});
				$("#_orderGrid").jqGrid('navGrid','#_orderBar',{add : false, del : false, edit : false, refresh : true, search : false});
				//jQuery.div.util.dialogInit("订单详情", "_ordersDetails", 880, 450);
		});
		
		function _auditOrder(id, status) {
			$("#orderId").val(id);
			$("#isPass").val((status==1 ? 0 : 1));
			$.post("${base}/order_auditOrder", 
				$('#_dataForm').serialize(), 
				function (response) {
					if (response && response.success) {
						alert(response.msg);
						$("#_orderGrid").jqGrid('setGridParam',{url: '${base}/order_getList/${shopId }'}).trigger("reloadGrid");
					} else {
						alert(response.msg);
					}
			}, "json");
		}
		
		function _back() {
			window.location.href = "${base }/shop_shopManagerList";
		}
		</script>
	<body>
	<div class="subScroll tree_subScroll" id="subScroll"><!-- 滚动条 -->
		<table cellpadding="0" cellspacing="0" border="0" width="99%" style="height:100%;">
			<tr><td style="height:10px; overflow:hidden;" colspan="2"></td></tr>
			<tr>
				<!--右边内容-->
				<td width="*" valign="top" class="contList">
					<!-- 显示商家列表 --> 
					<table id="_orderGrid"></table>
					<div id="_orderBar"></div>
					<div class="contBtn" style="width:900px; _width:902px;"><!--width 和id="_UserGrid"宽度设置一致;IE宽度需多加左右border的宽度-->
						<input type="button" value="返回" class="btn" onclick="_back();" />
					</div>
					<form id="_dataForm" style="margin-top: 20px;padding:2px;">
						<input name="orderId" id="orderId" value="" type="hidden" />
						<input name="isPass" id="isPass" value="1" type="hidden" />
					</form>
					<div id="_ordersDetails"></div><!--订单详情页面-->
				</td>
		</table>
	</div>
	</body>
</html>
